﻿using System.Collections.Generic;

namespace MyMovieCollection.DATA.Models
{
    public class PointScale
    {
        private static readonly IDictionary<int, PointScale> intToPointScale = new Dictionary<int, PointScale>()
                                                                                   {
                                                                                       {0,new PointScale(0,10,ALL,0)},
                                                                                       {1,new PointScale(0, 1.99, VERYBAD, 1)},
                                                                                       {2,new PointScale(2, 3.99, BAD, 2)},
                                                                                       {3,new PointScale(4,5.99,NOTBAD,3)},
                                                                                       {4,new PointScale(6,7.99,GOOD,4)},
                                                                                       {5,new PointScale(8,10,EXCELLENT,5)}
                                                                                   };

        private readonly double minPoint;
        private readonly double maxPoint;
        private readonly string scaleName;
        private readonly int scaleID;

        public PointScale(double minPoint, double maxPoint, string scaleName, int scaleID)
        {
            this.minPoint = minPoint;
            this.maxPoint = maxPoint;
            this.scaleName = scaleName;
            this.scaleID = scaleID;
        }


        public virtual double MinPoint
        {
            get { return minPoint; }
        }

        public virtual double MaxPoint
        {
            get { return maxPoint; }
        }

        public virtual string ScaleName
        {
            get { return scaleName; }
        }

        public virtual int ScaleID
        {
            get { return scaleID; }
        }

        public bool Equals(PointScale obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            return obj.minPoint == minPoint && obj.maxPoint == maxPoint && Equals(obj.scaleName, scaleName) && obj.scaleID == scaleID;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (PointScale)) return false;
            return Equals((PointScale) obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = minPoint.GetHashCode();
                result = (result*397) ^ maxPoint.GetHashCode();
                result = (result*397) ^ (scaleName != null ? scaleName.GetHashCode() : 0);
                result = (result*397) ^ scaleID;
                return result;
            }
        }

        public static List<PointScale> GetPointScales()
        {
            return new List<PointScale>(intToPointScale.Values);
        }

        public static PointScale ConvertToPointScale(int scale)
        {
            if (intToPointScale.ContainsKey(scale))
                return intToPointScale[scale];
            
            return new PointScale(0, 10, ALL, 0);
        }

        public const string ALL = "Lütfen Seçiniz";
        public const string VERYBAD = "Çok Kötü";
        public const string BAD = "Kötü";
        public const string NOTBAD = "Fena Sayılmaz";
        public const string GOOD = "İyi";
        public const string EXCELLENT = "Çok iyi";
    }
}